package com.learn.project2.controller.admin;

import com.learn.project2.model.bo.admin.admin.AdminCreateBO;
import com.learn.project2.model.bo.admin.admin.AdminUpdateBO;
import com.learn.project2.model.vo.admin.admin.AdminCreateVO;
import com.learn.project2.model.vo.admin.admin.AdminListVO;
import com.learn.project2.model.vo.admin.admin.AdminUpdateVO;
import com.learn.project2.service.admin.admin.AdminService;
import com.learn.project2.utils.AESUtil;
import com.learn.project2.utils.BaseParam;
import com.learn.project2.utils.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zhizhuke
 * @version 1.0
 * @description:
 * @date 2022-01-08 09-01
 */
@RestController
@RequestMapping("admin/admin")
public class AdminController {

    @Autowired
    AdminService adminService;


    /**
     * @description:
     * @param:
     * @return:
     * @author zhizhuke
     * @date: 2022-01-08 09:02
     */
    @RequestMapping("list")
    @RequiresPermissions(value = {"admin:admin:list"})
    public Result list(BaseParam param, String username) {
        AdminListVO adminListVO = adminService.list(param, username);
        return Result.ok(adminListVO);
    }

    /**
     * @description:
     * @param:
     * @return:
     * @author zhizhuke
     * @date: 2022-01-08 10:10
     */
    @RequestMapping("create")
    @RequiresPermissions(value = {"admin:admin:create"})
    public Result create(@RequestBody AdminCreateBO adminCreateBO, HttpServletRequest request) {
        AdminCreateVO createVO = adminService.create(adminCreateBO);
        return Result.ok(createVO);
    }

    @RequestMapping("update")
    @RequiresPermissions(value = {"admin:admin:update"})
    public Result update(@RequestBody AdminUpdateBO adminUpdateBO, HttpServletRequest request) {
        AdminUpdateVO adminUpdateVO = adminService.update(adminUpdateBO);
        return Result.ok(adminUpdateVO);
    }

    @RequestMapping("delete")
    @RequiresPermissions(value = {"admin:admin:delete"})
    public Result delete(@RequestBody AdminUpdateBO adminUpdateBO, HttpServletRequest request) {
        adminService.delete(adminUpdateBO);
        return Result.ok();
    }

}
